package com.zhangtai.modules.controller.member;

import com.alibaba.fastjson.JSONObject;
import com.zhangtai.modules.controller.aouthLogin.MemberLoginController;
import com.zhangtai.modules.dto.FundsRecordDto;
import com.zhangtai.modules.dto.SecurityRecordDto;
import com.zhangtai.modules.service.security.FundsRecordService;
import com.zhangtai.modules.service.security.SecurityRecordService;
import com.zhangtai.modules.vo.SecurityRecordVo;
import com.zhangtai.utils.PageResult;
import com.zhangtai.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Api(tags="社保公积金自助端")
@RequestMapping("/member")
@Slf4j
public class SecurityMemberController {


    @Autowired
    private SecurityRecordService securityRecordService;

    @Autowired
    private MemberLoginController memberLoginController;
    @Autowired
    private FundsRecordService fundsRecordService;

    @PostMapping("/getPersonSecurity")
    @ApiOperation("获取个人社保记录")
    public R<PageResult<SecurityRecordDto>> getPersonSecurity(HttpServletRequest request,@RequestBody(required = false) @Valid SecurityRecordVo securityRecordVo,@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
            ,@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)throws Exception{
        JSONObject data = memberLoginController.getUserInfo(request).getData();
        Long oid = data.getLong("id"); //只能查询自己的信息
//        Long oid =new Long(438520);
        PageResult<SecurityRecordDto> recordMap = securityRecordService.getRecordList(null,null, securityRecordVo.getIsCheck(), 1, securityRecordVo.getType(),null,
                null,oid.toString(),securityRecordVo.getName(),null,null, pageNum, pageSize);
        return R.ok(recordMap);
    }

    @PostMapping("/getPersonFunds")
    @ApiOperation("获取个人公积金记录")
    public R<PageResult<FundsRecordDto>> getPersonFunds(HttpServletRequest request,@RequestBody(required = false) @Valid SecurityRecordVo securityRecordVo,@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
            ,@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)throws Exception{
        JSONObject data = memberLoginController.getUserInfo(request).getData();
        Long oid = data.getLong("id"); //只能查询自己的信息
//        Long oid =new Long(438520);

        PageResult<FundsRecordDto> recordMap = fundsRecordService.getRecordList(null,null, securityRecordVo.getIsCheck(), 1, securityRecordVo.getType(),null,
                null,oid.toString(),securityRecordVo.getName(),null, pageNum, pageSize);
        return R.ok(recordMap);
    }
 }
